﻿#region 命名空间

using System;
using WinnerCMS.BLL;
using WinnerCMS.Common;
using WinnerCMS.Model;

#endregion

namespace WinnerCMS.WebUI.Templates.WinnerCMS6.Member
{
    public partial class Information : WebFactory.ClientPublicPage
    {
        private readonly Public_Member _myBLL = new Public_Member(false);

        protected void Page_Load(object sender, EventArgs e)
        {
            Page.Title = "资料修改";
            if (!IsPostBack)
            {
                var model = new UserManage().GetInfo(UserManage.Current.UserID);

                if (model != null)
                {
                    this.txtHomePage.Text = model.HomePage;
                    this.txtQQ.Text = model.QQ;
                    this.txtPetName.Text = model.PetName;
                    this.txtIntroduce.Text = model.Introduce;
                    this.txtemail.Text = model.EMail;

                    this.txtQuestion.Text = model.Question;
                    this.txtAnswer.Text = model.Answer;
                    this.RBL_Sex.SelectedValue = model.Sex.ToString();
                    this.txtTrueName.Text = model.TrueName;
                    this.txtMSN.Text = model.Msn;
                    this.txtBirthday.Text = model.Birthday;
                    //txtProvince.Text = model.Province;
                    //txtCity.Text = model.City;
                    this.txtICQ.Text = model.Icq;
                    this.txtYahoo.Text = model.Yahoo;
                    this.txtSkype.Text = model.Skype;
                    //txtLocation.Text = model.Location;
                    this.txtIdCard.Text = model.IdCard;
                    this.txtMobile.Text = model.Mobile;
                    this.txtPhone.Text = model.Phone;
                    this.txtAddress.Text = model.Address;
                }
            }
        }


        protected void btnEdit_Click(object sender, EventArgs e)
        {
            if (RightsCheck.IsLogined == false)
            {
                MsgBox.Message("登录超时，请重新登录。", "Login.aspx", this);
            }
            var model = new UserManage().GetInfo(UserManage.Current.UserID);


            model.HomePage = this.txtHomePage.Text.Trim();
            model.QQ = this.txtQQ.Text.Trim();
            model.PetName = this.txtPetName.Text.Trim();
            model.Introduce = this.txtIntroduce.Text.Trim();
            model.EMail = this.txtemail.Text.Trim();

            model.Question = this.txtQuestion.Text.Trim();
            model.Answer = this.txtAnswer.Text.Trim();
            model.Sex = byte.Parse(this.RBL_Sex.SelectedValue);
            model.TrueName = this.txtTrueName.Text.Trim();
            model.Msn = this.txtMSN.Text.Trim();

            model.Birthday = this.txtBirthday.Text.Trim();
            model.Province = string.Empty;
            model.City = string.Empty;
            model.Icq = this.txtICQ.Text.Trim();
            model.Yahoo = this.txtYahoo.Text.Trim();

            model.Skype = this.txtSkype.Text.Trim();
            model.Location = string.Empty;
            model.IdCard = this.txtIdCard.Text.Trim();
            model.Mobile = this.txtMobile.Text.Trim();
            model.Phone = this.txtPhone.Text.Trim();
            model.Address = this.txtAddress.Text.Trim();

            string Err = null;

            this._myBLL.EditByMemberSelf(model, ref Err);

            if (string.IsNullOrEmpty(Err) == false)
            {
                MsgBox.Message(Err, this.UpdatePanel1);
            }
            else
            {
                MsgBox.Message("修改成功!", this.UpdatePanel1);
            }
        }
    }
}